/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.sdgakj.service;

import com.sdgakj.dto.base.ResCode;

/**
 * Service层公用的Exception.
 * 
 * 继承自RuntimeException, 从由Spring管理事务的函数中抛出时会触发事务回滚.
 * 
 * @author calvin
 */
public class ServiceException extends RuntimeException {

    private static final long serialVersionUID = 3583566093089790852L;
    
    private ResCode resCode;
    
    public ResCode getResCode() {
        return resCode;
    }

    public void setResCode(ResCode resCode) {
        this.resCode = resCode;
    }
    
    public ServiceException(ResCode resCode) {
        super(resCode.resMsg);
        this.resCode = resCode;
    }
    
    public ServiceException(ResCode resCode, Throwable e) {
        super(resCode.resMsg, e);
        this.resCode = resCode;
    }


    public ServiceException() {
        super();
    }

    public ServiceException(String message) {
        super(message);
    }

    public ServiceException(Throwable cause) {
        super(cause);
    }

    public ServiceException(String message, Throwable cause) {
        super(message, cause);
    }
    
    /**
     * 可以任意设置错误信息
     * 
     * @param resCode
     * @param msg
     */
    public ServiceException(ResCode resCode, String msg) {
        super(msg);
        resCode.setResMsg(msg);
        this.resCode = resCode;
    }
}
